﻿using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using V_League.Public;
using V_League.DataAccess;
using V_League.Business;

namespace V_League.Pages
{
    /// <summary>
    /// Interaction logic for ManHinhChinh.xaml
    /// </summary>
    public partial class ManHinhChinh : UserControl
    {
        BTC_Public BTC_Pub;
        BTC_Business BTC_Bus;

        CLB_Business CLB_Bus;
        CLB_Public CLB_Pub;

        HLV_Public HLV_Pub;
        HLV_Business HLV_Bus;

        NTT_Public NTT_Pub;
        NTT_Business NTT_Bus;

        SANVD_Public SAN_Pub;
        SAN_Business SAN_Bus;

        DataTable DanhsachHLV;
        DataTable DanhsachNTT;
        DataTable DanhsachSan;
        public ManHinhChinh()
        {
            InitializeComponent();
            BTC_Pub = new BTC_Public();
            BTC_Bus = new BTC_Business();
            CLB_Pub = new CLB_Public();
            CLB_Bus = new CLB_Business();
            HLV_Pub = new HLV_Public();
            HLV_Bus = new HLV_Business();
            NTT_Pub = new NTT_Public();
            NTT_Bus = new NTT_Business();
            SAN_Pub = new SANVD_Public();
            SAN_Bus = new SAN_Business();
        }

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            String MaBTC = (String)Application.Current.Properties["idBTC"];
            BTC_Pub = BTC_Bus.GetInfo(MaBTC);
            DataTable dt = BTC_Bus.GetCLBTheoMaBTC(BTC_Pub) ;
            dtg_showCLB.ItemsSource = dt.DefaultView;
            lbUser.Content = "Xin chào " + BTC_Pub.Ten_BTC.ToString();
            btnSua.IsEnabled = false;
            btnThem.IsEnabled = false;
            btnXoa.IsEnabled = false;
        }

        private void dtg_showCLB_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DanhsachHLV = HLV_Bus.ListHLV();
            foreach (DataRow dtr1 in DanhsachHLV.Rows)
            {
                cbTenHLV.Items.Add(dtr1.ItemArray[0].ToString());
            }

            DanhsachNTT = NTT_Bus.ListNTT();
            foreach (DataRow dtr1 in DanhsachNTT.Rows)
            {
                cbNTT.Items.Add(dtr1.ItemArray[0].ToString());
            }

            DanhsachSan = SAN_Bus.ListSan();
            foreach (DataRow dtr1 in DanhsachSan.Rows)
            {
                cbSannha.Items.Add(dtr1.ItemArray[0].ToString());
            }
            DataRowView dtr = (DataRowView)dtg_showCLB.SelectedItem;
            if (dtr == null)
                return;
            txtMaCLB.Text = dtr.Row.ItemArray[0].ToString();
            txtTenBTC.Text = BTC_Pub.Ten_BTC;
            HLV_Pub = HLV_Bus.GetInfoHLV(dtr.Row.ItemArray[2].ToString());
            cbTenHLV.Text = HLV_Pub.Ten_HLV.ToString();
            SAN_Pub = SAN_Bus.GetInfoSAN(dtr.Row.ItemArray[3].ToString());
            cbSannha.Text = SAN_Pub.TenSan.ToString();
            NTT_Pub = NTT_Bus.GetInfoNTT(dtr.Row.ItemArray[4].ToString());
            cbNTT.Text = NTT_Pub.Ten_NTT.ToString();
            txtTenCLB.Text = dtr.Row.ItemArray[5].ToString();
            txtSoluongcauthu.Text = dtr.Row.ItemArray[6].ToString();
            txtTDPhuc.Text = dtr.Row.ItemArray[7].ToString();
            txtMaCLB.IsReadOnly = true;
            txtTenBTC.IsReadOnly = true;
            btnThem.IsEnabled = false;
            btnXoa.IsEnabled = true;
            btnSua.IsEnabled = true;
        }

        private void btnDangxuat_Click(object sender, RoutedEventArgs e)
        {
            NavigationCommands.GoToPage.Execute("/Pages/Home.xaml", this);
        }

        private void btnSua_Click(object sender, RoutedEventArgs e)
        {
            btnThem.IsEnabled = true;
            CLB_Pub.Ma_CLB = txtMaCLB.Text.ToString();
            
        }
    }
}
